﻿@using Nop.Core.Domain.Catalog
@model ProductModel.ProductVariantAttributeValueModel
@{
    Html.AddScriptParts("~/Scripts/farbtastic.js");
    Html.AddCssFileParts("~/Content/farbtastic/farbtastic.css");
}
@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.ProductVariantAttributeId)
@Html.HiddenFor(model => model.DisplayColorSquaresRgb)

@if (ViewBag.RefreshPage == true)
{
    <script type="text/javascript">
        try {window.opener.document.forms['@(ViewBag.formId)'].@(ViewBag.btnId).click();}
        catch (e){} 
        window.close();
    </script>
}
<script type="text/javascript">
    $(document).ready(function () {
        
        $("#@Html.FieldIdFor(model => model.AttributeValueTypeId)").change(toggleProductType);
        
        toggleProductType();
    });

    function toggleProductType() {
        var selectedProductTypeId = $("#@Html.FieldIdFor(model => model.AttributeValueTypeId)").val();
        if (selectedProductTypeId == @(((int)AttributeValueType.Simple).ToString())) {
            $('#group-associated-product').hide();
            $('#group-quantity').hide();
            $('#group-price-adjustment').show();
            $('#group-weight-adjustment').show();
            $('#group-cost').show();
        } else if (selectedProductTypeId == @(((int)AttributeValueType.AssociatedToProduct).ToString())) {
            $('#group-associated-product').show();
            $('#group-quantity').show();
            $('#group-price-adjustment').hide();
            $('#group-weight-adjustment').hide();
            $('#group-cost').hide();
        }
    }
</script>
<table class="adminContent">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.AttributeValueTypeId):
        </td>
        <td class="adminData">
            @Html.DropDownListFor(model => model.AttributeValueTypeId, ((AttributeValueType)Model.AttributeValueTypeId).ToSelectList())
            @Html.ValidationMessageFor(model => model.AttributeValueTypeId)
        </td>
    </tr>
    <tr id="group-associated-product">
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.AssociatedProductId):
        </td>
        <td class="adminData">
            @Html.HiddenFor(model => model.AssociatedProductId)
            <span id="associate-product-name">@Model.AssociatedProductName</span>
            @Html.ValidationMessageFor(model => model.AssociatedProductId)
            <input type="submit" value=@T("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Values.Fields.AssociatedProduct.AddNew") onclick="javascript:OpenWindow('@(Url.Action("AssociateProductToAttributeValuePopup", "Product", new { productIdInput = Html.FieldIdFor(model => model.AssociatedProductId), productNameInput = "associate-product-name" }))', 800, 800, true); return false;" class="k-button" />
        </td>
    </tr>
    <tr id="group-quantity">
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.Quantity):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.Quantity)
            @Html.ValidationMessageFor(model => model.Quantity)
        </td>
    </tr>
</table>
@(Html.LocalizedEditor<ProductModel.ProductVariantAttributeValueModel, ProductModel.ProductVariantAttributeValueLocalizedModel>("productattributevalue-localized",
@<table class="adminContent">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.Locales[item].Name):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.Locales[item].Name)
            @Html.ValidationMessageFor(model => model.Locales[item].Name)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            @Html.HiddenFor(model => model.Locales[item].LanguageId)
        </td>
    </tr>
</table>
,
@<table class="adminContent">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.Name):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </td>
    </tr>
</table>
      ))
<table class="adminContent">
    @if (Model.DisplayColorSquaresRgb)
    {
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ColorSquaresRgb):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.ColorSquaresRgb)
                <div id="color-picker"></div>
                <script type="text/javascript">
                    $(document).ready(function(){
                        $('#color-picker').farbtastic('#@Html.FieldIdFor(model => model.ColorSquaresRgb)');
                    });
                </script>
                @Html.ValidationMessageFor(model => model.ColorSquaresRgb)
            </td>
        </tr>
    }
    <tr id="group-price-adjustment">
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.PriceAdjustment):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.PriceAdjustment)
            @Html.ValidationMessageFor(model => model.PriceAdjustment)
        </td>
    </tr>
    <tr id="group-weight-adjustment">
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.WeightAdjustment):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.WeightAdjustment)
            @Html.ValidationMessageFor(model => model.WeightAdjustment)
        </td>
    </tr>
    <tr id="group-cost">
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.Cost):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.Cost)
            @Html.ValidationMessageFor(model => model.Cost)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.IsPreSelected):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.IsPreSelected)
            @Html.ValidationMessageFor(model => model.IsPreSelected)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.DisplayOrder):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.DisplayOrder)
            @Html.ValidationMessageFor(model => model.DisplayOrder)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.PictureId):
        </td>
        <td class="adminData">
            <ul style="list-style: none;">
                <li style="float: left; width: 110px;">
                    <p style="float: left; padding-top: 20px;">
                        <input type="radio" name="@Html.FieldNameFor(x => x.PictureId)" value="0" id="id_image_0"
                                @if (Model.PictureId == 0)
                                {
                                    <text>checked="checked"</text>
                                }>
                    </p>
                    <p style="float: left; padding-top: 20px;">
                        <label for="id_image_0">
                            @T("Admin.Catalog.Products.ProductVariantAttributes.Attributes.Values.Fields.Picture.NoPicture")
                        </label>
                    </p>
                </li>
                @foreach (var picture in Model.ProductPictureModels)
                {
                    <li style="float: left; width: 110px;">
                        <p style="float: left; padding-top: 20px;">
                            <input type="radio" name="@Html.FieldNameFor(x => x.PictureId)" value="@picture.PictureId" id="id_image_@picture.PictureId"
                                @if (picture.PictureId == Model.PictureId)
                                {
                                    <text>checked="checked"</text>
                                }>
                        </p>
                        <p style="float: left;">
                            <label for="id_image_@picture.PictureId">
                                <img src="@picture.PictureUrl" alt="" title="" width="75">
                            </label>
                        </p>
                    </li>
                }
            </ul>
            @Html.ValidationMessageFor(model => model.PictureId)
        </td>
    </tr>
</table>

